package com.lwf.component.spider.iteye.boke;

import com.lwf.core.processor.Handler;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.selector.Selectable;

import java.util.List;
@Component
public class IteyeBokeetailListHandler implements Handler {
    public String getUrlRegex() {
        return "^http://www.iteye.com/blogs\\?page=[0-9]+$";
    }

    public synchronized void process(Page page) {
        List<Selectable> nodes = page.getHtml().xpath("/html/body/div/div[2]/div[1]/div[2]/div").nodes();
        for (Selectable node : nodes) {
            String link = node.xpath("div/h3/a").links().get();
            page.addTargetRequest(link);
        }
        String nextUrl = page.getHtml().css("html body div#page div#content.clearfix div#main div#index_main div.pagination a.next_page").links().get();
        page.addTargetRequest(nextUrl);

    }
}
